//
// C++ Implementation: activitytablemodel
//
// Description:
//
//
// Author: Willi Ballenthin <wilbal1087@gmail.com>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "activitytablemodel.h"

ActivityTableModel::ActivityTableModel ( QVector<Activity>* vector,  QObject *parent )
        : QAbstractTableModel ( parent )
{
    this->vector = vector;
}


ActivityTableModel::~ActivityTableModel()
{
}

int ActivityTableModel::rowCount ( const QModelIndex & /*parent*/) const
{
    return vector->size();
}

int ActivityTableModel::columnCount ( const QModelIndex & /*parent*/) const
{
    return Activity::visibleFields;
}

QVariant ActivityTableModel::data ( const QModelIndex & index, int /*role*/) const
{

    {
        switch ( index.column() )
        {
            case 0:
                return vector->value(index.row() ).getDate();
                break;
            case 1:
                return vector->value(index.row() ).getTime();
                break;
            case 2:
                return vector->value(index.row() ).getDuration();
                break;
            case 3:
                return vector->value(index.row() ).getDistance();
                break;
            case 4:
                return vector->value(index.row() ).getEffort();
                break;
            case 5:
                return vector->value(index.row() ).getType();
                break;
            case 6:
                return vector->value(index.row() ).getLocation();
                break;
            case 7:
                return vector->value(index.row() ).getRoute();
                break;
            case 8:
                return vector->value(index.row() ).getNotes();
                break;
            case 9:
                return vector->value(index.row() ).getSplits();
                break;
            default:
                return 0;
        }
    }

}

QVariant ActivityTableModel::headerData ( int section, Qt::Orientation orientation, int /*role*/) const
{
    if ( orientation == Qt::Horizontal )   // column names
    {
        switch ( section )
        {
            case 0:
                return "Date";
                break;
            case 1:
                return "Time";
                break;
            case 2:
                return "Duration";
                break;
            case 3:
                return "Distance";
                break;
            case 4:
                return "Effort";
                break;
            case 5:
                return "Type";
                break;
            case 6:
                return "Location";
                break;
            case 7:
                return "Route";
                break;
            case 8:
                return "Notes";
                break;
            case 9:
                return "Splits";
                break;
            default:
                return 0;
        }
    }
    else    // row names
    {
        return section;
    }
}
